package org.ms.mtx.example.service.cannel;

import org.apache.commons.lang3.StringUtils;
import org.ms.mtx.example.service.StockService;
import org.springframework.stereotype.Service;

/**
 * 库存服务
 *
 * @author lry
 */
@Service
public class StockCancelService {

    public Boolean stockCancel(Integer number, String exceptionMock) {
        if (StringUtils.isNotBlank(exceptionMock) && exceptionMock.equals(Thread.currentThread().getStackTrace()[1].getMethodName())) {
            throw new RuntimeException("模拟异常:" + Thread.currentThread().getStackTrace()[1].getMethodName());
        }

        System.out.println("回滚库存:库存从[" + StockService.stock.get() + "]增加为[" + StockService.stock.addAndGet(number) + "]");
        return true;
    }

}
